<?php

namespace app\api\controller;


class Temperatures extends Base
{
    public function initialize()
    {
        parent::initialize();
        $this->checkOauth();
    }

    public function contents_submit()
    {
        $id          = input('id') ?: 2;

        $temperature = (float)input('temperature');

        if ($temperature) {
            $res = influx_save([['temperature' => $temperature]], ['userid' => $id]);
        } else {
            return js_return(0, 'error');
        }

        return $res ? js_return(1, 'success', []) : js_return(0, 'insert failed');
    }


    public function get_tsdata()
    {
        $id   = input('id') ?: 2;
        $data = influx_get(['userid' => $id]);

        return $data ? js_return(1, 'success', $data) : js_return(0, 'insert failed');
    }
}
